using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.Rendering;
using UnityEditor.EditorTools;
using Codice.Client.Common;
using lights.polytool.editor;
using UnityEditor.Overlays;
using UnityEditor.UIElements;
using Unity.VisualScripting.YamlDotNet.Serialization;

namespace lights.polytool.editor
{
    [CustomEditor(typeof(comp_polymesh))]
    public class inspector_poly : Editor
    {

        public override void OnInspectorGUI()
        {
            var taget = this.target as comp_polymesh;
            if (taget == null)
            {
                return;
            }
            var m = GUILayout.Toggle(taget.mirror, "IsMirror");
            if (m != taget.mirror)
            {
                taget.mirror = m;
                taget.Bake();
            }
            GUILayout.BeginHorizontal();
            GUILayout.Label("height",GUILayout.Width(80));
            var height = GUILayout.HorizontalSlider(taget.height, 0.025f, 10.0f);
            if (height != taget.height)
            {
                taget.height = height;
                taget.Bake();
            }

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            var usestep = GUILayout.Toggle(taget.useStep, "UseStep", GUILayout.Width(80));
            if (usestep != taget.useStep)
            {
                taget.useStep = usestep;
                taget.Bake();
            }
            if (usestep)
            {
                var stepheight = GUILayout.HorizontalSlider(taget.heightStep, 0.025f, 10.0f);
                if (stepheight != taget.heightStep)
                {
                    taget.heightStep = stepheight;
                    taget.Bake();
                }
            }
            GUILayout.EndHorizontal();
            //base.OnInspectorGUI();

            GUILayout.Label("This is QuickMesh Editor tool.");
            GUILayout.BeginHorizontal();
            GUILayout.Space(10);

            if (GUILayout.Button("Bake"))
            {
                taget.Bake();
            }
            if (this.editor != null && this.editor.active)
            {
                if (GUILayout.Button("StopEditPoly"))
                {
                    editor.EndEdit();
                    taget.Bake();

                }
            }
            else if (GUILayout.Button("EditPoly"))
            {
                if (editor == null)
                    editor = new polyeditor();
                editor.BeginEdit(taget);

            }
            GUILayout.EndHorizontal();
        }

        private polyeditor editor = null;

        void OnSceneGUI()
        {
            editor?.Draw();
        }


    }
}
